package com.sskj.fca.ui.activity;

import android.support.v4.content.ContextCompat;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.bulong.rudeness.RudenessScreenHelper;
import com.sskj.common.adapter.slimadapter.IViewInjector;
import com.sskj.common.adapter.slimadapter.SlimAdapter;
import com.sskj.common.adapter.slimadapter.SlimInjector;
import com.sskj.common.base.App;
import com.sskj.common.box.decoration.DividerHorizenLineItemDecoration;
import com.sskj.lib.RConfig;
import com.sskj.lib.base.BaseActivity;
import com.sskj.fca.R;
import com.sskj.fca.bean.CommonBean;
import com.sskj.fca.presenter.PlayIntroducePresenter;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

@Route(path = RConfig.APP_PLAY_INTEODUCE)//玩法介紹
public class PlayIntroduceActivity extends BaseActivity<PlayIntroducePresenter> {
    @BindView(R.id.recyclerView)
    RecyclerView recyclerView;
    private SlimAdapter slimAdapter;

    @Override
    protected int getLayoutResId() {
        return R.layout.app_activity_play_introduce;
    }

    @Override
    public PlayIntroducePresenter getPresenter() {
        return new PlayIntroducePresenter();

    }

    @Override
    protected void initView() {
        setTitle("玩法介紹");

        mPresenter.getCommonData();
        recyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
        recyclerView.addItemDecoration(new DividerHorizenLineItemDecoration(this
                )
                        .setFirstDraw(false)
                        .setLastDraw(false)
                        .setTopPadding((int) RudenessScreenHelper.pt2px(App.INSTANCE, 13))
                        .setBottomPadding((int) RudenessScreenHelper.pt2px(App.INSTANCE, 13))
                        .setPaintWidth((int) RudenessScreenHelper.pt2px(App.INSTANCE, 0.6f))
                        .setPaintColor(ContextCompat.getColor(App.INSTANCE, R.color.app_f2f))
        );
        slimAdapter = SlimAdapter.create().register(R.layout.app_recy_item_expand_child, new SlimInjector<CommonBean.PlayInfoBean.GameBean>() {
            @Override
            public void onInject(CommonBean.PlayInfoBean.GameBean data, IViewInjector injector, List payloads) {
                injector.text(R.id.tv_child_title, data.getTitle())
                        .text(R.id.tv_child_content, data.getContent().replaceAll("\\|","\n"));
            }
        }).attachTo(recyclerView).updateData(new ArrayList());
    }

    public void updataUI(CommonBean commonBean) {
        CommonBean.PlayInfoBean play_info = commonBean.getPlay_info();
        List<CommonBean.PlayInfoBean.GameBean> game = play_info.getGame();
        slimAdapter.updateData(game);
    }

}
